1
|
|
|
/** |
2
|
|
|
* [Siteapp] - multi-purpose application & CMS theme |
3
|
|
|
* |
4
|
|
|
* Siteapp debugger |
5
|
|
|
* |
6
|
|
|
* @package [Siteapp] |
7
|
|
|
* @subpackage [Siteapp] core |
8
|
|
|
* @author Björn Bartels <[email protected]> |
9
|
|
|
* @link https://gitlab.bjoernbartels.earth/groups/themes |
10
|
|
|
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 |
11
|
|
|
* @copyright copyright (c) 2016 Björn Bartels <[email protected]> |
12
|
|
|
* |
13
|
|
|
* @namespace Siteapp |
14
|
|
|
* @module Siteapp.Debugger |
15
|
|
|
*/ |
16
|
|
|
/** global: Siteapp */ |
17
|
|
|
|
18
|
|
|
var Debugger = { |
19
|
|
|
/* manage debug data */ |
20
|
|
|
debugentries : [], |
21
|
|
|
|
22
|
|
|
types : ['log', 'debug', 'info', 'warn', 'error'], |
23
|
|
|
|
24
|
|
|
add : function ( oEntry ) { |
25
|
|
|
var entry = { |
26
|
|
|
type : oEntry.type || 'info', |
27
|
|
|
message : oEntry.message || '', |
28
|
|
|
time : oEntry.time || (new Date()) |
29
|
|
|
}; |
30
|
|
|
this.debugentries.push(entry); |
31
|
|
|
return (this); |
32
|
|
|
}, |
33
|
|
|
|
34
|
|
|
clear : function ( ) { |
35
|
|
|
this.debugentries = []; |
36
|
|
|
return (this); |
37
|
|
|
}, |
38
|
|
|
|
39
|
|
|
toEntry : function ( ) { |
40
|
|
|
var entry = arguments; |
41
|
|
|
if (entry.length == 1) { |
42
|
|
|
entry[1] = entry[0]; |
43
|
|
|
entry[0] = 'info'; |
44
|
|
|
} |
45
|
|
|
return { |
46
|
|
|
type : entry[0] || 'info', |
47
|
|
|
message : entry[1] || '', |
48
|
|
|
time : (new Date()), |
49
|
|
|
}; |
50
|
|
|
}, |
51
|
|
|
|
52
|
|
|
debug : function ( ) { |
53
|
|
|
if ( (console || (typeof console.debug == 'function')) && $LCARS.getInstance().config.debug ) { |
|
|
|
|
54
|
|
|
console.debug(arguments); |
55
|
|
|
} |
56
|
|
|
return (this); |
57
|
|
|
}, |
58
|
|
|
|
59
|
|
|
log : function ( msg ) { var entry = this.toEntry('log', msg); this.add(entry).console(entry); return (this); }, |
60
|
|
|
|
61
|
|
|
info : function ( msg ) { var entry = this.toEntry('info', msg); this.add(entry).console(entry); return (this); }, |
62
|
|
|
|
63
|
|
|
warn : function ( msg ) { var entry = this.toEntry('warn', msg); this.add(entry).console(entry); return (this); }, |
64
|
|
|
|
65
|
|
|
error : function ( msg ) { var entry = this.toEntry('error', msg); this.add(entry).console(entry); return (this); }, |
66
|
|
|
|
67
|
|
|
console : function ( data ) { |
68
|
|
|
if (!console || !data || !data.type || !data.message || !data.time || !$LCARS.getInstance().config.debug) { |
|
|
|
|
69
|
|
|
return (this); |
70
|
|
|
} |
71
|
|
|
var txt = [ |
72
|
|
|
String(data.type).toUpperCase(), ': ', |
73
|
|
|
String(data.message), ' - ', |
74
|
|
|
String(data.time), '' |
75
|
|
|
].join(''); |
76
|
|
|
if ( (typeof console[data.type] == 'function') ) { |
77
|
|
|
console[data.type](txt); |
78
|
|
|
} else { |
79
|
|
|
//console.//log(txt); |
80
|
|
|
} |
81
|
|
|
return (this); |
82
|
|
|
}, |
83
|
|
|
|
84
|
|
|
get : function ( ) { |
85
|
|
|
if (arguments.length === 0) { |
86
|
|
|
return ( this.debugentries ); |
87
|
|
|
} else if (arguments.length == 1) { |
88
|
|
|
var entries = []; |
89
|
|
|
for ( var iEntry in this.debugentries ) |
|
|
|
|
90
|
|
|
if ( this.debugentries[iEntry].type == arguments[0] ) |
|
|
|
|
91
|
|
|
entries.push( this.debugentries[iEntry] ); |
|
|
|
|
92
|
|
|
return ( entries ); |
93
|
|
|
} |
94
|
|
|
return (false); |
95
|
|
|
}, |
96
|
|
|
|
97
|
|
|
getInstance : function ( ) { |
98
|
|
|
return (this); |
99
|
|
|
}, |
100
|
|
|
|
101
|
|
|
_app : ( context ) => { |
102
|
|
|
if (context) { |
103
|
|
|
this.__app = context; |
|
|
|
|
104
|
|
|
} else { |
105
|
|
|
return this.__app; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
}; |
110
|
|
|
|
111
|
|
|
export {Debugger}; |
112
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.